package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.dto.ResultMsg;
import cn.sdormitory.smartclass.entity.AdClassAttence;
import cn.sdormitory.smartclass.entity.ClassHygiene;
import cn.sdormitory.smartclass.service.ClassAttenceService;
import cn.sdormitory.smartclass.service.ClassHygieneService;
import cn.sdormitory.smartclass.vo.ClassAttenceVo;
import cn.sdormitory.smartclass.vo.ClassHygieneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @创建人：zhouyang
 * @创建时间：2021/12/20 15:33
 * @version：V1.0
 */
@RestController
@RequestMapping("/app/ClassHygiene")
@Api("APP端班级卫生管理接口")
public class AppClassHygieneController {
    @Autowired
    private ClassHygieneService classHygieneService;
    @ApiOperation("getAppClaHyByCId => 查询某班级当日某时间段的卫生情况")
    @GetMapping(value = "/getAppClaHyByCId")
    public ResultMsg getAppClaHyByCId(Long classId, String accessDate,String timeSlot){
        ClassHygieneVo classHygieneVo=classHygieneService.getClassHygieneInfo(classId,accessDate,timeSlot);
        return ResultMsg.BY_SUCCESS("获取成功",classHygieneVo);
    }

    @ApiOperation("create => APP端新增班级卫生信息")
    @PostMapping(value = "/createClassHygiene")
    public CommonResult<Integer> create(@RequestBody ClassHygiene classHygiene) throws IOException {
        int count=0;
        if(classHygiene.getId()!=null && classHygiene.getId()>0){
            count = classHygieneService.update(classHygiene);
        }else{
            count = classHygieneService.create(classHygiene);
        }
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
